<?php
$iCat = getValue('iCat','int','GET',0);

$db = new DBQuery;
//Đếm số bản ghi
$total_record = $db->numRecord('SELECT new_id FROM news WHERE new_cat_id = '.$iCat);
// khai báo Phân trang
$page_size		= 3;
$page_current   = 0;
$action = getValue('action','str','POST','');
if($action === 'paging'){
    $page_current = getValue('page_current','int','POST',0);
}
if($total_record%$page_size){
	$page_total = ($total_record - $total_record%$page_size)/$page_size+1;
}
else
    $page_total = $total_record/$page_size;
//Phân trang


//Select tên của thư mục
$catname = $db->loadResult('SELECT cat_name FROM categories_news WHERE cat_id = '.$iCat);
//Select các bản ghi
$catnews = $db->query('SELECT   new_id,
                                new_title,
                                new_image,
                                new_content_summary,
                                new_date 
                                FROM news 
                       WHERE new_cat_id = '.$iCat. '
                       LIMIT '.$page_current.','.$page_size);


?>
<div class="wrapContent_news">
    <div class="tabContent">
    	<h2 class="tabContentTitle"><?php echo $catname ?></h2>
    </div>
    <div class="mainContent2">
    <?php if($catnews) foreach($catnews as $anew):?>
    	<div class="news1">
    		<img class="fl" src="<?php echo ($anew['new_image']) ? $path_img_news . $anew['new_image'] : $path_img_site.'noimages.png'?>"/>
    		<h2 class="news1Title"><a href="<?=generate_detail_url('news',$anew)?>"><?php echo $stringhelper->CropWord($anew['new_title'],10)?></a></h2>
    		<div class="newsCont"><?php  echo $stringhelper->CropWord($anew['new_content_summary'],45)?></div>
    	</div>
    <?php endforeach; 
        else echo 'Chuyên mục này chưa có bài viết';?>
    </div>
    <div class="btn_content">Hiển thị thêm tin tức</div>
</div>
<script>
$('.mainContent2').jScrollPane();
var page_current = 1;
var page_total = <?php echo $page_total?>;
var data = {name:'page_cat_news'};
$('.btn_content').click(function(){
    if(page_current < page_total){
        var iCat = '<?php echo base64_encode($iCat) ?>';
        data.iCat = iCat;
        data.page_current = page_current;
 //       loadModule('.mainContent2',data,false);
        $.ajax({
            type:'POST',
            url:'ctrlmod',
            data:data,
            success:function(result){
                $('.jspPane').append(result);
                $('.mainContent2').jScrollPane();
            }
        })
        $('.mainContent2').jScrollPane();
        page_current++;    
    }
    else alert('Đây là trang cuối');
    
});

</script>